package DMSXL._2024.BinaryTrees;

import java.util.ArrayList;
import java.util.List;
import java.util.NavigableMap;

public class getMinimumDifference {
    public static void main(String[] args) {
        Integer[] nums = {4,0,6,1,3};
        TreeNode root = CreateTree.createBinaryTree(nums,0);
        System.out.println(new getMinimumDifference().getMinimumDifference(root));
    }
    int max = Integer.MAX_VALUE;
    TreeNode pre = null;

    public int getMinimumDifference(TreeNode root) {
        if(root == null){
            return 0;
        }
        inorder(root);

        return max;

    }
    public void inorder(TreeNode root){
        if(root == null){
            return;
        }
        inorder(root.left);
        if(pre != null){
            max = Math.min(Math.abs(pre.val - root.val),max);
        }
        pre = root;
        inorder(root.right);
    }

}
